package com.jbm.jbmsupplier.activity.activitymanag;

import android.os.Handler;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.widget.ImageView;
import android.widget.TextView;

import com.jbm.jbmsupplier.R;
import com.jbm.jbmsupplier.activity.AllActivityApp;
import com.jbm.jbmsupplier.activity.activitymanag.presenter.NewHomeActivityma;
import com.jbm.jbmsupplier.activity.activitymanag.view.NewHomeViewma;
import com.jbm.jbmsupplier.adapter.FragmentAdapter;
import com.jbm.jbmsupplier.frement.ListFrement;
import com.jbm.jbmsupplier.utlis.ExitActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by 家帮忙 on 2017/8/28.
 */

public class Activity_Manage extends AllActivityApp implements NewHomeViewma {

    @InjectView(R.id.teleft)
    TextView teleft;
    @InjectView(R.id.tetitle)
    TextView tetitle;
    @InjectView(R.id.toolbar_image)
    ImageView toolbarImage;
    @InjectView(R.id.to_custro)
    Toolbar toCustro;
    @InjectView(R.id.tabs)
    TabLayout tabs;
    @InjectView(R.id.viewpagerfb)
    ViewPager viewpagerfb;
    private NewHomeActivityma newHomeActivitys;
    private ArrayList<Fragment> fragments;
    final String Order_Type_new = "new";
    final String Order_Type_break = "break";
    final String Order_Type_confirm = "confirm";
    final String Order_Type_submit = "submit";
    final String Order_Type_payed="payed";
    @Override
    public int setContentView() {
        return R.layout.newhomeac_lzmanage;
    }

    @Override
    public void initIalizeView() {
        ButterKnife.inject(this);
        ExitActivity.getInstance().addActivity(this);
        newHomeActivitys = new NewHomeActivityma(this, this);
        newHomeActivitys.setInitMode();
        tetitle.setText("管理端");
    }


    @OnClick(R.id.teleft)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void getLoadTitle() {
        setTitle("待确认", "作业中", "未结算","已结算", 1);
    }



    public interface getDateTypes {//施工段接口s
        void setType(int i, String sta);
    }

    @Override
    public void getExit(String name, Handler handler, int obj, int tag) {
        if (tag == 1) {
            hint(name, handler, obj);
        }
    }

    @Override
    public TextView getTextUser() {
        return null;
    }

    public void setTitle(String name, String name1, String name2,String name3, final int tag) {//设置标题栏
        List<String> titles = new ArrayList<>();
        titles.add(name);
        titles.add(name1);
        titles.add(name2);
        titles.add(name3);
        for (int i = 0; i < titles.size(); i++) {
            tabs.addTab(tabs.newTab().setText(titles.get(i)));
        }
        fragments = new ArrayList<>();
        for (int i = 0; i < titles.size(); i++) {

            fragments.add(new ListFrement());


        }

        FragmentAdapter mFragmentAdapteradapter = new FragmentAdapter(getSupportFragmentManager(), fragments, titles);
        //给ViewPager设置适配器
        viewpagerfb.setAdapter(mFragmentAdapteradapter);
        //将TabLayout和ViewPager关联起来。
        tabs.setupWithViewPager(viewpagerfb);
        //给TabLayout设置适配器
        tabs.setTabsFromPagerAdapter(mFragmentAdapteradapter);

        viewpagerfb.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                String mQueryStatus = null;
                switch (position) {
                    case 0:
                        mQueryStatus = "'" + Order_Type_new + "','" + Order_Type_break + "'";
                        break;
                    case 1:
                        mQueryStatus = "'" + Order_Type_confirm + "'";
                        break;
                    case 2:
                        mQueryStatus = "'" + Order_Type_submit + "'";
                        break;
                    case 3:
                        mQueryStatus = "'" + Order_Type_payed + "'";
                        break;
                }
                ((ListFrement) fragments.get(position)).setType(position, mQueryStatus);


            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }

}
